﻿export default () => {
  // 1) 统一的时间区间配置
  const TIME_RANGE_CFG = {
    label: "新增时间",
    component: "el-date-picker",
    type: "daterange",
    format: "YYYY-MM-DD",
    valueFormat: "YYYY-MM-DD",
  };
  // 搜索配置
  const searchOption = ref({
    formConfig: {
      categoryName: {
        label: "类目名称",
        component: "el-input",
      },
      timeRange: { ...TIME_RANGE_CFG }, // 固定在这个位置显示

      // 编辑时间
      updateTime: {
        label: "编辑时间",
        component: "el-date-picker",
        type: "daterange",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
      },
      // 操作人员
      updateName: {
        label: "操作人员",
        component: "el-input",
      },
    },
  });

  const tableOption = ref(
    Utils.tools.deleteSearchConfig({
      addTitle: "新增公告类目",
      editTitle: "编辑公告类目",
      // 弹窗宽度
      dialogWidth: "30%",
      // 是否显示编辑按钮
      editBtn: false,
      // 是否显示删除按钮
      delBtn: false,
      // 菜单宽度 单个按钮 52px 按钮容器内边距 8px 例如：4个按钮 = 52 * 4 * 8
      menuWidth: 52 * 3 + 8,
      // 对齐方式
      align: "left",
      group: [
        {
          column: {
            categoryName: {
              label: "类目名称",
              span: 24,
              placeholder: "请输入类目名称",
              type: "input",
              maxlength: 20,
              clearable: true,
              rules: [
                { required: true, message: "请输入类目名称", trigger: "blur" },
                { min: 1, max: 20, message: "最多 20 个字符", trigger: "blur" },
              ],
            },
            indexSort: {
              label: "类目排序",
              span: 24,
              type: "number",
              controls: false,
              placeholder: "请输入排序，限制正整数，越小排越前",
              rules: [
                { required: true, message: "请输入类目排序", trigger: "blur" },
                {
                  validator: (_r, v, cb) => (/^[1-9]\d*$/.test(String(v)) ? cb() : cb(new Error("请输入正整数"))),
                  trigger: "blur",
                },
              ],
            },
            // 4) 适用对象（必选，至少勾选一项；保存时已在页面 hook 里拼接为逗号）
            target: {
              label: "适用对象",
              span: 24,
              type: "checkbox",
              dicData: [], // ← 页面里动态填
              dicProps: { label: "label", value: "value" },
              rules: [
                { required: true, type: "array", message: "请至少选择一个适用对象", trigger: "change" },
                {
                  validator: (_r, v, cb) =>
                    Array.isArray(v) && v.length > 0 ? cb() : cb(new Error("请至少选择一个适用对象")),
                  trigger: "change",
                },
              ],
              // dicUrl: "/support-backend/dict/listChildrenByDictCode",
              // dicQuery: { dictCode: "qingyun.support.serviceCenter.applicableObject" }, // 按文档拼写
              // dicFormatter: res => {
              //   const list = Array.isArray(res) ? res : [];
              //   return list.map(i => ({ label: i.dictLabel, value: i.dictValue }));
              // },

              // rules: [
              //   { required: true, type: "array", message: "请至少选择一个适用对象", trigger: "change" },
              //   {
              //     validator: (_r, v, cb) =>
              //       Array.isArray(v) && v.length > 0 ? cb() : cb(new Error("请至少选择一个适用对象")),
              //     trigger: "change",
              //   },
              // ],
            },
          },
        },
      ],
      column: {
        indexSort: {
          label: "排序",
          span: 24,
          type: "number",
          controls: false,
          addDisplay: false,
          placeholder: "请输入排序，限制正整数，越小排越前",
          rules: [
            { required: true, message: "请输入类目排序", trigger: "blur" },
            {
              validator: (_r, v, cb) => (/^[1-9]\d*$/.test(String(v)) ? cb() : cb(new Error("请输入正整数"))),
              trigger: "blur",
            },
          ],
        },
        categoryName: { label: "类目名称", minWidth: 160, display: false },
        targetName: {
          label: "适用对象",
          minWidth: 160,
          display: false,
          addDisplay: false,
        },

        count: { label: "公告数量", minWidth: 160, display: false, addDisabled: true },
        createTime: {
          label: "新增时间",
          minWidth: 170,
          type: "datetime",
          valueFormat: "YYYY-MM-DD HH:mm:ss",
          addDisplay: false,
          editDisplay: false,
        },
        updateTime: {
          label: "最近编辑时间",
          minWidth: 170,
          type: "datetime",
          valueFormat: "YYYY-MM-DD HH:mm:ss",
          addDisplay: false,
          editDisplay: false,
        },
        updateName: {
          label: "最近编辑人",
          minWidth: 120,
          addDisplay: false,
          editDisplay: false,
        },
      },
    })
  );
  return { searchOption, tableOption };
};
